package com.hilinos.gb.gb28181.repository.mysql.mapper.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.util.Date;
import java.util.Map;

/**
 * @author qhl
 * @since 2022-01-05
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel("设备表")
@TableName("device_info")
public class Device {

    public static final String STATUS_ONLINE = "1";
    public static final String STATUS_OFFLINE = "2";

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("设备编号 deviceId 必须大于 4 位并且小于 32 位")
    @TableId("device_id")
    private String deviceId;
    @ApiModelProperty("设备名称 deviceName 必须小于 32 位")
    @TableField("device_name")
    private String deviceName;
    @ApiModelProperty("生产厂商 manufacturer 必须小于 64 位")
    private String manufacturer;
    @ApiModelProperty("型号 manufacturer 必须小于 64 位")
    private String model;
    @ApiModelProperty("固件版本 firmware 必须小于 64 位")
    private String firmware;
    @ApiModelProperty("通信协议 protocol 必须小于 16 位")
    private String protocol;
    @ApiModelProperty("SIP 传输协议 transport 必须为 3 位")
    private String transport;
    @ApiModelProperty("数据流传输模式 streamMode 必须小于 16 位")
    @TableField("stream_mode")
    private String streamMode;
    @ApiModelProperty("IP地址 streamMode 必须小于 15 位")
    private String ip;
    @ApiModelProperty("端口号 port 最大值为 65535")
    private Integer port;
    @ApiModelProperty("在线状态 online 必须为 1 位")
    private String online;
    @ApiModelProperty("通道数量 channelSum 最大值为 1000000000")
    @TableField("channel_sum")
    private Integer channelSum;
    @ApiModelProperty("创建时间 ")
    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    @ApiModelProperty("注册时间 ")
    @TableField("register_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date registerTime;
    @ApiModelProperty("心跳时间 ")
    @TableField("heartbeat_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date heartbeatTime;
    @ApiModelProperty("更新时间 ")
    @TableField("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime = new Date();
    @ApiModelProperty("修改人 ")
    @TableField("update_person")
    private String updatePerson;
    @ApiModelProperty("同步时间 ")
    @TableField("sync_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date syncTime;
    @ApiModelProperty("同步人 ")
    @TableField("sync_person")
    private String syncPerson;
    @ApiModelProperty("用户名 username 必须小于 32 位")
    private String username;
    @ApiModelProperty("密码 password 必须小于 32 位")
    private String password;


    @TableField(exist = false)
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private Host host;

    public Host getHost() {
        return Host.builder()
                .ip(getIp())
                .port(port)
                .build();
    }

    @TableField(exist = false)
    private Map<String, DeviceChannel> channelMap;

}